package com.sdy.web;

import com.alibaba.fastjson.JSONObject;
import com.sdy.po.SerialPO;
import com.sdy.po.User;
import com.sdy.service.SerialService;
import com.sdy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/userInfo")
public class UserController {

    @Autowired
    UserService userService;

    @Autowired
    SerialService serialService;

    /**
     * 用户信息页面
     * @param session
     * @param model
     * @return
     */
    @RequestMapping("")
    public String userInfo(HttpSession session , Model model){
        JSONObject jsonObject = new JSONObject();
        User user = (User) session.getAttribute("loginUser");
        model.addAttribute("loginUser",user);

        //串口信息
        List<SerialPO> serialList = serialService.findByComandId(user.getCompanyId());
        if (serialList.size() > 0){
            model.addAttribute("Serials",serialList);
            jsonObject.put("Serials",true);
        }


        model.addAttribute("results",jsonObject);

        return "pages/userInfo";
    }
}
